package com.yebxxx.server.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yebxxx.server.pojo.EmployeeRemove;
import com.yebxxx.server.pojo.PageBean;
import com.yebxxx.server.pojo.RespBean;
import com.yebxxx.server.pojo.SysMsgContent;
import com.yebxxx.server.service.ISysMsgContentService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author stx
 * @since 2022-03-23
 */
@RestController
@RequestMapping("/sys-msg-content")
public class SysMsgContentController {
    @Autowired
    private ISysMsgContentService sysMsgContentService;

    @ApiOperation(value = "添加留言")
    @PostMapping("/")
    public RespBean addSysMsgContent(SysMsgContent sysMsgContent){
        sysMsgContent.setCreateDate(LocalDateTime.now());
        if(sysMsgContentService.save(sysMsgContent)){
            return  RespBean.success("添加成功");
        }
        return RespBean.error("添加失败");
    }
    @ApiOperation(value = "删除留言")
    @DeleteMapping("/")
    public RespBean deleteSysMsgContent(Integer id){
        if(sysMsgContentService.removeById(id)){
            return  RespBean.success("删除成功！");
        }
        return RespBean.error("删除失败!");
    }

    @ApiOperation(value = "修改留言")
    @PostMapping("/update")
    public RespBean updateSysMsgContent(SysMsgContent sysMsgContent){
        sysMsgContent.setCreateDate(LocalDateTime.now());
        if(sysMsgContentService.updateById(sysMsgContent)){
            return  RespBean.success("修改成功！");
        }
        return RespBean.error("修改成功!");
    }
    @ApiOperation(value = "查询留言")
    @GetMapping("/")
    public PageBean findAllSysMsgContent(@RequestParam(defaultValue = "1" )Integer currentPage,
                                         @RequestParam(defaultValue = "10")Integer size,
                                SysMsgContent sysMsgContent) {
        return sysMsgContentService.sysMsgContentList(currentPage, size, sysMsgContent);
    }
//    @ApiOperation(value = "修改留言")
//    @PostMapping("/update")
//    public RespBean updateSysMsgContent(SysMsgContent sysMsgContent){
//      if(sysMsgContentService.updateById(sysMsgContent)){
//          return  RespBean.success("修改成功！");
//      }
//      return RespBean.error("修改失败！");
//    }


}
